/*
Creates subset of worker-year panel with spells in our subset of establishments 
		// input: workeryear_panel; estabtreat_forRAIS_deid
		// output: quitsnewhires
*/

cap log close
cap log using "$logs/create_allworkers_sample", replace 

*****************
* Create dataset of all workers (worker-year panel)
*****************

use "$files/rais/BR/workeryear_panel.dta", clear
drop atblemp*


*****************
* Merge with treatment variable at the worker level
* Only keep workers who were at a treated or control employer at a given point in time
*****************

merge m:1 fakeid_estab using "$files/estabtreat_forRAIS_deid.dta"
keep if _merge==3
drop _merge

* Baseline information on single establishment firms and employing both genders
gen xxx = singest if year==2014
gegen bl_singest = max(xxx), by(fakeid_estab)
drop xxx
count if singest!=bl_singest

gen xxx = both_FM if year==2014
gegen bl_bothFM = max(xxx), by(fakeid_estab)
drop xxx
count if both_FM!=bl_bothFM

gen xxx = signing if year==2014
gegen bl_signing = max(xxx), by(fakeid_estab)
drop xxx

gen xxx = covered if year==2014
gegen bl_covered = max(xxx), by(fakeid_estab)
drop xxx


xtset fakeid_worker year
save "$files/quitsnewhires.dta", replace


cap log close
